

#include <head.h>

int main(int argc, char const *argv[])
{
    
    pid_t pid =0;
    if (-1 == (pid = fork()))
    {
        ERRLOG("进程创建失败");
        exit(0);
    }
    if (pid >0)
    {
        exit(0);
    }
    if (setsid()==-1)
    {
        ERRLOG("会话创建失败");
        exit(0);
    }
    if (chdir("/")==-1)
    {
        ERRLOG("目录切换失败");
        exit(0);
    }
    umask(0);
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);
    
    while (1)
    {
        FILE *fp = fopen("/tmp/test.txt","a+");
        if (fp == NULL)
        {
            ERRLOG("文件打开失败");
            exit(0);
        }
        time_t t = time(NULL);
        fprintf(fp,"%s %s\n",ctime(&t),"hello world");
        fclose(fp);

        sleep(5);
    }
    return 0;
}